#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)


//https://leetcode.cn/problems/sort-an-array/
class Solution {

    int getrandom(vector<int>& nums, int left, int right)
    {
        srand(time(NULL));

        return nums[rand() % (right - left + 1) + left];
    }
    void sqort(vector<int>& nums, int l, int r)
    {
        if (l >= r)
            return;
        int key = getrandom(nums, l, r);

        int i = l, left = l - 1, right = r + 1;
        while (i < right)
        {
            if (nums[i] < key)
            {
                swap(nums[++left], nums[i++]);
            }
            else if (nums[i] == key)
            {
                i++;
            }
            else
            {
                swap(nums[--right], nums[i]);
            }
        }
        //[l,left],[left+1,right-1],[right,r]
        sqort(nums, l, left);
        sqort(nums, right, r);
    }
public:
    vector<int> sortArray(vector<int>& nums) {
        sqort(nums, 0, nums.size() - 1);
        return nums;
    }
};